<template>
    <bi-form ref="form">
        <bi-form-item label="标签">
            <bi-input v-model="form.title" required></bi-input>
        </bi-form-item>
        <bi-form-item label="分组">
            <bi-select v-model="form.group_id" required>
                <bi-select-option v-for="(item,index) in groupList" :key="index" :value="item.group_id" :label="item.title"></bi-select-option>
            </bi-select>
        </bi-form-item>
    </bi-form>
</template>

<script>
export default{
    data(){
        let form = {
            title:'',
            group_id:'',
        }

        form = this.$assign(form,this.item);
        return {
            form,
            groupList:[]
        }
    },
    props:{
        item:Object
    },
    methods:{
        dialogOk(){

            if (this.$refs.form.check()){
                this.$ajax({
                    url:this.$url({action:'saveTag'}),
                    data:this.form,
                    success:()=>{
                        this.$toast('保存成功');
                        this.dialog.callback();
                        this.dialog.close();
                    }
               });
            }

            return false;
        },
        getGroupList(){
            this.$ajax({
                url:this.$url({action:'groupList'}),
                success:(res)=>{
                    this.groupList = res;
                }
            })
        },
    },
    mounted(){
        this.getGroupList();
    }
}
</script>